package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Property;
import com.ruoyi.system.domain.Time;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Vip;
import com.ruoyi.system.service.IVipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员管理Controller
 * 
 * @author ruoyi
 * @date 2024-12-11
 */
@RestController
@RequestMapping("/system/vip")
public class VipController extends BaseController
{
    @Autowired
    private IVipService vipService;

    /**
     * 查询会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:vip:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vip vip)
    {
        startPage();
        List<Vip> list = vipService.selectVipList(vip);
        startPage();
        List<Long> num = vipService.selectNum();
        for(int i = 0; i < list.size(); i++){
            list.get(i).setVipOrderNum(num.get(i));
        }
        return getDataTable(list);
    }


    /**
     * 导出会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:vip:export')")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vip vip)
    {
        List<Vip> list = vipService.selectVipList(vip);
        ExcelUtil<Vip> util = new ExcelUtil<Vip>(Vip.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:vip:query')")
    @GetMapping(value = "/{vipId}")
    public AjaxResult getInfo(@PathVariable("vipId") Long vipId)
    {
        return success(vipService.selectVipByVipId(vipId));
    }

    @PreAuthorize("@ss.hasPermi('system:vip:query')")
    @GetMapping(value="/orderInfo")
    public AjaxResult getOrderInfo(String vipName, String vipTel)
    {
        System.out.println(vipService.selectOrdeList(vipName,vipTel));
        return success(vipService.selectOrdeList(vipName,vipTel));
    }



    /**
     * 新增会员管理
     */
    @PreAuthorize("@ss.hasPermi('system:vip:add')")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vip vip)
    {
        return toAjax(vipService.insertVip(vip));
    }

    /**
     * 修改会员管理
     */
    @PreAuthorize("@ss.hasPermi('system:vip:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vip vip)
    {
        return toAjax(vipService.updateVip(vip));
    }

    /**
     * 删除会员管理
     */
    @PreAuthorize("@ss.hasPermi('system:vip:remove')")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vipIds}")
    public AjaxResult remove(@PathVariable Long[] vipIds)
    {
        return toAjax(vipService.deleteVipByVipIds(vipIds));
    }
}
